package net.dgg.zz.production.inProcess.controller;

import com.alibaba.fastjson.JSONArray;
import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.iboss.base.util.CustomerNumberEncryptionUtil;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.iboss.base.util.JsonUtil;
import net.dgg.iboss.base.util.datatable.DataTableUtils;
import net.dgg.iboss.base.util.datatable.domain.DataTableRequest;
import net.dgg.iboss.base.util.datatable.domain.DataTableResponse;
import net.dgg.iboss.base.util.http.HttpUtility;
import net.dgg.tmd.foundation.platform.annotation.AuthOpt;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import net.dgg.tmd.foundation.platform.session.SessionManager;
import net.dgg.tmd.foundation.platform.user.entity.UserDTO;
import net.dgg.tmd.foundation.platform.user.entity.UserEntity;
import net.dgg.zz.common.constant.ApiUrlConstant;
import net.dgg.zz.common.constant.CredentialConstant;
import net.dgg.zz.common.constant.ScProductConstant;
import net.dgg.zz.common.entity.Node;
import net.dgg.zz.common.excption.CommonExcption;
import net.dgg.zz.common.service.CommonMangerExtService;
import net.dgg.zz.common.service.CommonService;
import net.dgg.zz.common.service.FlowService;
import net.dgg.zz.common.systemRecord.entity.SystemRecord;
import net.dgg.zz.common.systemRecord.service.SystemRecordService;
import net.dgg.zz.common.utils.DateUtils;
import net.dgg.zz.common.utils.OrderHandleUtils;
import net.dgg.zz.common.utils.StringUtils;
import net.dgg.zz.common.utils.excel.ExcelUtils;
import net.dgg.zz.credential.certificateType.service.CertificateTypeService;
import net.dgg.zz.credential.externalFunction.service.ProductReservationService;
import net.dgg.zz.credential.generalCredential.entity.CommonVo;
import net.dgg.zz.credential.generalCredential.entity.GeneralCertificate;
import net.dgg.zz.credential.generalCredential.service.GeneralCredentialService;
import net.dgg.zz.credential.guidePriceConfigure.service.GuidePriceConfigService;
import net.dgg.zz.credential.qualification.entity.Qualification;
import net.dgg.zz.credential.qualification.service.QualificationService;
import net.dgg.zz.production.all.service.AllOrderService;
import net.dgg.zz.production.entity.ProductOrder;
import net.dgg.zz.production.excption.ProductOrderExcption;
import net.dgg.zz.production.inProcess.entity.Assistant;
import net.dgg.zz.production.inProcess.entity.ProductNode;
import net.dgg.zz.production.inProcess.service.ZzInProcessService;
import net.dgg.zz.production.vo.AbnormalOrderVo;
import net.dgg.zz.production.vo.InprocessOrderVo;
import net.dgg.zz.production.vo.WaitAuditOrderVo;
import net.dgg.zz.production.vo.WaitAuditOrderWjVo;
import net.fblock.log.NLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>@Title 办理中Controller s六号号</p>
 * <p>@Description 办理中相关</p>
 * <p>@Version 1.0.0 版本号</p>
 * <p>@author maoquanyi</p>
 * <p>@date 2018年08月13日</p>
 * <p>Copyright © dgg group.All Rights Reserved. 版权信息</p>
 */
@Controller
@RequestMapping("/zzsc/inprocess")
public class ZzInProcessController extends DggBaseController {

    //新的引入
    @Resource
    private ZzInProcessService zzInProcessService;
    @Resource
    private SystemRecordService systemRecordService;
    @Resource
    private CommonService commonService;
    @Resource
    private GeneralCredentialService generalCredentialService;
    @Resource
    private ProductReservationService reservationService;//预约
    @Resource
    private CertificateTypeService certificateTypeService;
    @Resource
    private QualificationService qualificationService;
    @Resource
    private GuidePriceConfigService guidePriceConfigService;
    @Resource
    private CommonMangerExtService zzCommonMangerExtService;
    @Resource
    private SessionManager sessionManager;
    @Resource
    private DesUtil desUtil;
    @Resource
    private TranslateUtil translateUtil;
    @Autowired
    private CommonMangerExtService commonMangerExtService;
    @Autowired
    private AllOrderService allOrderService;
    @Autowired
    private FlowService flowService;
    @Value("${scGdzxApiUrl}")
    private String scGdzxApiUrl;

    /**
     * <p>@Description 初始化界面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/13 0013 11:27 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/index")
    @NLog()
    public String index(Model model, String status) {
        model.addAttribute("status", !StringUtils.isEmpty(status) ? status : "all");
        model.addAttribute("all", "all"); //全部办理中
        /*model.addAttribute("toDay", "toDay"); //今日待跟进
        model.addAttribute("hasOverDue", "hasOverDue"); //已超期跟进
        model.addAttribute("nodeOverDue", "nodeOverDue"); //节点已超期
        model.addAttribute("proOverDue", "proOverDue"); //订单已超期*/
        model.addAttribute("overDue", "overDue");//已超期
        model.addAttribute("currentDay", "currentDay"); //新增办理
        model.addAttribute("overdueWarning", "overdueWarning"); //即将超期
        return "zzsc/inprocess/inprocess_list";
    }


    /**
     * <p>@Description 办理中信息分页列表</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/13 0013 16:47 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/query_in_processList")
    @ResponseBody
    @NLog()
    public DataTableResponse queryBusinessList(@RequestParam Map params, HttpServletRequest request) {
        try {
            UserEntity userEntity = sessionManager.getCurrentUser();
            DataTableRequest r = DataTableUtils.getParam(request); //获取datatable参数
            params.put("start", r.getStart());//获取当前页
            params.put("limit", r.getLength());//获取每页条数
            params.put("scstatus", ScProductConstant.SC_ORDER_IN_PROCESS);//办理中#
            params.put("dept", "dept");
            params.put("userEntity", userEntity.getId()); //当前登录人
            if (StringUtils.isNotEmpty(params.get("customerPhone"))) {
                params.put("customerPhone", desUtil.encrypt(params.get("customerPhone").toString()));
            }
            Map fileMap = new HashMap();
            fileMap.put("orderTime", "orderTime");
            fileMap.put("lastRemarkTime", "lastRemarkTime");
            OrderHandleUtils.getOrderCol(r, params, fileMap);
            //获取判断界面展示内容的key
            getAcquisitionConditions(params);
            List<Map> listPage = zzInProcessService.queryInProcessListPage(params);
            String[] transColum = {"originCode", "originType", "status", "businessTypeId", "businessProductId"};
            listPage = translateUtil.translateList(transColum, listPage);//翻译
            String[] hideColum = {"customerPhone"};//解密
            listPage = desUtil.decryptListMap(hideColum, listPage);
            CustomerNumberEncryptionUtil.encryptionList(hideColum, listPage);
            Integer count = Integer.parseInt(params.get("count").toString());
            return new DataTableResponse(r.getDraw(), count, count, listPage, "");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 查询我的已完结生产订单列表
     *
     * @return
     */
    @RequestMapping("/get_close_audit_order")
    @ResponseBody
    public DataTableResponse getCloseAuditOrder(@RequestParam Map params, HttpServletRequest request) {
        try {
            DataTableRequest r = DataTableUtils.getParam(request); //获取datatable参数
            params.put("start", r.getStart());//获取当前页
            params.put("limit", r.getLength());//获取每页条数
            if (net.dgg.zz.common.utils.StringUtils.isNotEmpty(params.get("customerPhone"))) {
                params.put("customerPhone", desUtil.encrypt(params.get("customerPhone").toString()));
            }
            if ("overOrder".equals(params.get("status"))) {
                params.put("all", null);
                params.put("status", null);
                String[] statusArray = new String[3];
                statusArray[0] = ScProductConstant.SC_ORDER_OVER;
                statusArray[1] = ScProductConstant.SC_ORDER_OVER_OVERDUE;
                statusArray[2] = ScProductConstant.SC_ORDER_OVER_FORCE;
                params.put("statusArr", statusArray);
                params.put("dataAuthority", "zzsc_sc_completed");
            } else {
                params.put("isQgj", "qgj");
                //获取判断界面展示内容的key
                getAcquisitionConditions(params);
            }
            params.put("scstatus", ScProductConstant.SC_ORDER_IN_PROCESS);//办理中#
            Map fileMap = new HashMap();
            fileMap.put("lastRemarkTime", "lastRemarkTime");
            OrderHandleUtils.getOrderCol(r, params, fileMap);
            List<Map> listPage = zzInProcessService.queryInProcessQgjListPage(params);
            String[] transColum = {"originCode", "originType", "status", "businessTypeId", "businessProductId"};
            listPage = translateUtil.translateList(transColum, listPage);//翻译
            String[] hideColum = {"customerPhone"};//解密
            listPage = desUtil.decryptListMap(hideColum, listPage);
            CustomerNumberEncryptionUtil.encryptionList(hideColum, listPage);
            Integer count = Integer.parseInt(params.get("count").toString());
            return new DataTableResponse(r.getDraw(), count, count, listPage, "");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 导出数据
     */
    @RequestMapping("/export_close_audit_sczz_completed")
    public void queryInProcessList(@RequestParam Map params, HttpServletResponse response) {
        try {
            if (net.dgg.zz.common.utils.StringUtils.isNotEmpty(params.get("customerPhone"))) {
                params.put("customerPhone", desUtil.encrypt(params.get("customerPhone").toString()));
            }
            String name = "待审核";
            String isOver = params.get("status") == null ? null : params.get("status").toString();
            if ("overOrder".equals(isOver)) {
                params.put("all", null);
                params.put("status", null);
                String[] statusArray = new String[3];
                statusArray[0] = ScProductConstant.SC_ORDER_OVER;
                statusArray[1] = ScProductConstant.SC_ORDER_OVER_OVERDUE;
                statusArray[2] = ScProductConstant.SC_ORDER_OVER_FORCE;
                params.put("statusArr", statusArray);
                params.put("dataAuthority", "zzsc_sc_completed");
                name = "已审核";
            } else {
                params.put("isQgj", "qgj");
                //获取判断界面展示内容的key
                getAcquisitionConditions(params);
            }
            params.put("scstatus", ScProductConstant.SC_ORDER_IN_PROCESS);//办理中#
            Map fileMap = new HashMap();
            fileMap.put("lastRemarkTime", "lastRemarkTime");
            String fileName = name + "订单_" + DateUtils.dateString(new Date(), "yyyyMMddHHmm") + ".xlsx";
            List dataList = new ArrayList<>();
            if ("overOrder".equals(isOver)) {
                dataList = zzInProcessService.queryInProcessWjList(params);
            } else {
                dataList = zzInProcessService.queryInProcessList(params);
            }
            String[] transColum = {"status"};
            dataList = translateUtil.translateList(transColum, dataList);//翻译
            if ("overOrder".equals(isOver)) {
                ExcelUtils.writeToFile(dataList, null, fileName, response, WaitAuditOrderWjVo.class);
            } else {
                ExcelUtils.writeToFile(dataList, null, fileName, response, WaitAuditOrderVo.class);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * <p>@Description 查询流程人员</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/5 0005 17:22 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/flow_user_data")
    @ResponseBody
    public Object getAllFlowUser() {
        Map<String, Object> map = new HashMap<>();
        //获取当前用户
        UserEntity user = sessionManager.getCurrentUser();
        map.put("orgId", user.getOrgId());//如果是最上级就取当前部门ID
        //查询当前部门的事业部
        Map mapot = commonMangerExtService.findBusDeptById(user.getOrgId());
        if (mapot != null && mapot.size() != 0) {
            map.put("orgId", mapot.get("id"));
        }
        return commonMangerExtService.searchUserByMap(map);
    }

    /**
     * <p>@Description 跳转到生产订单详情</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/20 0020 11:26 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("/product_detail_page")
    @NLog()
    public String index(@RequestParam Map params, Model model) {
        try {
            Map<String, Object> resultMap = zzInProcessService.queryScBaseInfo(params);
            if (!params.containsKey("type")) {
                model.addAttribute("type", 0);
            } else {
                model.addAttribute("type", 1);
            }
            String btnArray = params.get("btnArray") == null ? "" : params.get("btnArray").toString();
            model.addAttribute("resultMap", resultMap);
            model.addAttribute("btnArray", btnArray);
            model.addAttribute("beforeTableName", params.get("beforeTableName"));
            model.addAttribute("beforeTableUrl", params.get("beforeTableUrl"));
            model.addAttribute("scGdzxApiUrl", scGdzxApiUrl);
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
        return "/zzsc/inprocess/product_detail_page";
    }

    /**
     * <p>@Description 通过客户ID查电话</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/13 0013 14:40 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/find_phone_by_customer_id")
    @ResponseBody
    @NLog()
    public DggRestResponse findPhoneByCustomerId(Long customerId) {
        try {
            String phoneByCustomerId = zzInProcessService.findPhoneByCustomerId(customerId);
            if (StringUtils.isNotEmpty(phoneByCustomerId)) {
                return this.getSuccessResponse(phoneByCustomerId);
            }
            return this.getFailResponse("未获取到该客户的电话号码!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 验证是否有权限详情编辑</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/17 0017 13:40 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/check_is_flower_or_assister")
    @ResponseBody
    @NLog()
    public DggRestResponse checkIsFlowerOrAssister(@RequestParam Map params) {
        try {
            zzInProcessService.checkIsFlowerOrAssister(params);
            return this.getSuccessResponse("验证通过!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 详情里面的保存</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_product_order_data")
    @ResponseBody
    @NLog()
    public DggRestResponse saveProductOrderData(@RequestParam Map params) {
        try {
            zzInProcessService.saveProductOrderData(params);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 验证更新节点前信息，以及判断弹出那个业态的界面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/15 0015 10:21 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/validation_update_node")
    @ResponseBody
    @NLog()
    public Object validationUpdateNode(Long id) {
        try {
            //------------判断当前登录人是否有操作权限--------
            this.zzInProcessService.validationUpdateNode(id);
            return this.getSuccessResponse("验证通过!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 更新节点弹出框</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/15 0015 9:13 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/open_update_node")
    @NLog()
    public ModelAndView openUpdateNode(Long id) {
        ModelAndView map = new ModelAndView();
        // 取得分配给负责人状态去页面对比
        map.addObject("allotway", ScProductConstant.ALLOT_TO_PRODUCT_USER);
        ProductOrder productOrder = zzInProcessService.getScProductOrderById(id);
        String statusArr = productOrder.getStatus();
        //查节点
        if (StringUtils.isEmpty(productOrder.getFlowContent())) {
            List<ProductNode> proNodes = new ArrayList<>();
            List<ProductNode> nodelist = zzInProcessService.queyNodeList(productOrder.getNodeFlowId());
            for (ProductNode scProductNode : nodelist) {
                if (null != scProductNode.getName() && !"".equals(scProductNode.getName()) && !"接单".equals(scProductNode.getName()) && !"分配".equals(scProductNode.getName())) {
                    proNodes.add(scProductNode);
                }
            }
            map.addObject("nodelist", proNodes);
        } else {
            List<Node> nodelist1 = flowService.getNode(id);
            List<Node> proNodes1 = new ArrayList<>();
            for (Node scProductNode1 : nodelist1) {
                if (null != scProductNode1.getName() && !"".equals(scProductNode1.getName()) && !"接单".equals(scProductNode1.getName()) && !"分配".equals(scProductNode1.getName())) {
                    proNodes1.add(scProductNode1);
                }
            }
            map.addObject("nodelist", proNodes1);
        }

        UserEntity user = sessionManager.getCurrentUser();
        //查询要更新的完成节点
        Map nodeMap = new HashMap();
        // nodeMap = flowService.getCurrentNode(productOrder);
        //
        if (ScProductConstant.SC_TO_RECEIVE_ZDDJS.equals(statusArr) || ScProductConstant.SC_TO_RECEIVE_YJDJS.equals(statusArr) || ScProductConstant.SC_TO_RECEIVE_TDDJS.equals(statusArr)) {
            List<Node> nodelist1 = flowService.getNode(id);
            List<Node> proNodes1 = new ArrayList<>();
            for (Node scProductNode1 : nodelist1) {
                if ("接单".equals(scProductNode1.getName())) {
                    proNodes1.add(scProductNode1);
                    nodeMap.put("id", scProductNode1.getId().toString());
                    nodeMap.put("name", scProductNode1.getName());
                    break;
                }
            }
        } else {
            if ("完结".equals(productOrder.getCurrentNodeName()) || "强制完结".equals(productOrder.getCurrentNodeName())) {
                nodeMap.put("id", null != productOrder.getLatestEndNodeId() ? productOrder.getLatestEndNodeId() : "");
                nodeMap.put("name", null != productOrder.getLatestEndNodeName() ? productOrder.getLatestEndNodeName() : "");
            } else {
                nodeMap.put("id", null != productOrder.getCurrentNodeId() ? productOrder.getCurrentNodeId() : "");
                nodeMap.put("name", null != productOrder.getCurrentNodeName() ? productOrder.getCurrentNodeName() : "");
            }
        }
        Node nextNode = new Node();
        if (!StringUtils.isEmpty(productOrder.getFlowContent())) {
            nextNode = flowService.getNextMustNode((String) nodeMap.get("id"), id);
        }
        //查档案绑定记录
        List<Map> filesRecordMap = zzInProcessService.queryFilesRecord(productOrder.getId().toString());
        map.addObject("filesRecordMap", filesRecordMap);
        map.addObject("productOrder", productOrder);
        map.addObject("code", productOrder.getBusinessTypeCode());
        map.addObject("flowType", commonService.queryTreeBook("FLOW_TYPE", 1, 2, null));
        map.addObject("nodeMap", nodeMap);
        map.addObject("nextNode", nextNode);
        map.addObject("user", user);
        map.addObject("preFlowType", productOrder.getFlowType());
        map.setViewName("/zzsc/inprocess/open_update_node");
        return map;
    }


    /**
     * <p>@Description 根据节点id查询对应的关联字段</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/15 0015 10:21 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/return_drop_down")
    @ResponseBody
    @NLog()
    public Object returnDropDown(String nodeid, Long id) {
        if (StringUtils.isEmpty(nodeid)) {
            return this.getSuccessResponse("");
        }
        HashMap result = new HashMap();
        try {
            ProductOrder productOrder = zzInProcessService.getScProductOrderById(id);
            //先通过节点ID 查节点
            if (StringUtils.isEmpty(productOrder.getFlowContent())) {

                //先通过节点ID 查节点
                List<ProductNode> nodelist = zzInProcessService.queyNodeListById(Long.valueOf(nodeid));
                if (nodelist == null) {
                    return getFailResponse("未查询到此节点信息相关信息");
                }
                //获取节点对应的关联字段
                result.put("relationfieldids", nodelist.get(0).getRelationFieldIds());
            } else {
                Node node = flowService.queyNodeListById(nodeid, id);
                if (null == node) {
                    return getFailResponse("未查询到此节点信息相关信息");
                }
                //获取节点对应的关联字段
                result.put("relationfieldids", node.getRelationFieldTypes());
            }

            return this.getSuccessResponse(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    /**
     * <p>@Description 保存更新节点功能</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/15 0015 10:30 创建时间</p>
     * <p>@return</p>
     */
    @AuthOpt(code = "SC_GENERAL_UPDATE_NODE")
    @RequestMapping("/save_node_update")
    @ResponseBody
    @NLog()
    public Object saveNodeUpdate(@RequestParam Map params) {
        try {
            UserEntity userEntity = sessionManager.getCurrentUser();
            int returnType = this.zzInProcessService.saveNodeUpdate(params, userEntity);
            return this.getSuccessResponse(returnType);
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("操作失败！");
        }
    }


    /**
     * <p>@Description 打开生产暂停</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/16 0016 15:10 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/suspend_order_page")
    @NLog()
    public String suspendOrderPage(Long id, Model model) {
        try {
            ProductOrder scProductOrder = this.zzInProcessService.getScProductOrderById(id);
            model.addAttribute("scProductOrder", scProductOrder);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "zzsc/inprocess/suspend_order_page";
    }

    /**
     * <p>@Description 保存生产暂停</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/16 0016 15:18 创建时间</p>
     * <p>@return</p>
     */
    @AuthOpt(code = "SC_GENERAL_SUSPEND")
    @RequestMapping("/suspend_pro_order")
    @ResponseBody
    @NLog()
    public Object suspendProOrder(@RequestParam Map params) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            UserEntity userEntity = sessionManager.getCurrentUser();
            String expectOpenTime = params.get("expectOpenTime").toString();
            if (new Date().getTime() > sdf.parse(expectOpenTime).getTime()) {
                return this.getFailResponse("预计开始时间小于当前时间!");
            }
            this.zzInProcessService.suspendProOrder(params, userEntity);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 打开添加协单，获取数据</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/16 0016 16:26 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("/add_assist_page")
    @NLog()
    public String addAssistPage(Long id, Model model) {
        try {
            //-------------获取当前生产订单数据---------------------------------
            ProductOrder scProductOrder = zzInProcessService.getScProductOrderById(id);
            StringBuilder ids = new StringBuilder();
            StringBuilder names = new StringBuilder();
            model.addAttribute("scProductOrder", scProductOrder);
            //-------------获取当前生产订单协单人员数据--------------------------
            List<Assistant> scAssistantList = zzInProcessService.queyScAssistantList(id);
            if (scAssistantList != null && !scAssistantList.isEmpty()) {
                for (Assistant scAssistant : scAssistantList) {
                    ids.append(scAssistant.getAssistUserId().toString().concat(","));
                    names.append(scAssistant.getAssistUserName().concat(","));
                }
                model.addAttribute("ids", ids.deleteCharAt(ids.lastIndexOf(",")));
                model.addAttribute("names", names.deleteCharAt(names.lastIndexOf(",")));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "zzsc/inprocess/add_assist_page";
    }


    /**
     * <p>@Description 保存添加的协单人员</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 20:12 创建时间</p>
     * <p>@return</p>
     */
    @AuthOpt(code = "SC_GENERAL_ADD_ASSIST")
    @RequestMapping(value = "/update_assist")
    @ResponseBody
    @NLog()
    public Object updateAssist(Long productOrderId, String assistIds) {
        try {
            UserEntity userEntity = sessionManager.getCurrentUser();
            this.zzInProcessService.updateAssist(productOrderId, assistIds, userEntity, null);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 生产详情查人员信息</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/22 0022 10:49 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("/assist_info")
    @NLog()
    public String assistInfo(@RequestParam Map params, Model model) {
        try {
            if (StringUtils.isNotEmpty(params.get("scorderId"))) {
                Long id = Long.valueOf(params.get("scorderId").toString());
                List<Assistant> flowUserList = zzInProcessService.queyScAssistantList(id);
                //构建查询日志条件
                Map<String, Object> map = new HashMap<>();
                map.put("source", 2);
                map.put("workId", id);
                int[] operateTypeArr = {24, 26, 29, 30};
                map.put("operateTypeArr", operateTypeArr);
                List<SystemRecord> recordsUserList = systemRecordService.findByParamsWithPage(map);
                model.addAttribute("flowUserList", flowUserList);
                model.addAttribute("recordsUserList", recordsUserList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "zzsc/inprocess/assist_info";
    }

    /**
     * <p>@Description 详情的历史记录生产备注iframe 页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/23 0023 14:23 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("/product_order_history_records")
    @NLog()
    public String productOrderHistoryRecords(Long scorderId, Long flowId, Model model) {
        ProductOrder productOrder = zzInProcessService.getScProductOrderById(scorderId);
        if (StringUtils.isEmpty(productOrder.getFlowContent())) {
            List<ProductNode> nodelist = zzInProcessService.queyNodeList(productOrder.getNodeFlowId());
            model.addAttribute("productNodes", nodelist);
        } else {
            List<Node> productNodes = new ArrayList<>();
            try {
                productNodes = flowService.getNode(scorderId);
            } catch (Exception e) {
                System.out.println("通过生产订单id获取流程节点");
                e.printStackTrace();
            }
            model.addAttribute("productNodes", productNodes);
        }

        List<Map> allRemarksNodeList = zzInProcessService.queryNodeAndRemarksNode(scorderId);
        ProductOrder scProductOrder = zzInProcessService.getScProductOrderById(scorderId);
        model.addAttribute("scProductOrderStatus", scProductOrder.getStatus());
        model.addAttribute("scorderId", scorderId);
        model.addAttribute("allRemarksNodeList", allRemarksNodeList);
        return "zzsc/inprocess/product_order_history_records";
    }

    /**
     * <p>@Description 详情页历史记录中的生产节点记录数据</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/23 0023 14:45 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/query_product_operating_list")
    @ResponseBody
    @NLog()
    public DggRestResponse queryProductOperatingList(@RequestParam Map params, HttpServletRequest request) {
        DataTableRequest r = DataTableUtils.getParam(request); //获取datatable参数
        params.put("page", r.getPage());//获取当前页
        params.put("limit", r.getLength());//获取每页条数
        List<Map> productNodeOperatingList = zzInProcessService.queryProductOperatingList(params);
        String[] transColum = {"flowType"};
        productNodeOperatingList = translateUtil.translateList(transColum, productNodeOperatingList);
        return new net.dgg.zz.common.utils.DataTableResponse().data(params, productNodeOperatingList);
    }

    /**
     * <p>@Description 详情里面资质证书 iframe页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/29 0029 18:33 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("/certificate_qualification_detail")
    @NLog()
    public String certificateQualificationDetail(Long scOrderId, Model model) {
        model.addAttribute("scOrderId", scOrderId);
        //查询已预约的证书
        Map<String, Object> storageMap = new HashMap<>();
        storageMap.put("scProductId", scOrderId);
        storageMap.put("generalType", CredentialConstant.GENERAL_CREDENTIAL);
        storageMap.put("status", CredentialConstant.PRODUCT_RESERVATION_STATUS_RESERVATION);//新增预约
        List<Map> reservationList = reservationService.queryListByScOrderId(storageMap);
        String[] transColum = {"certificateCategory", "certificateToThree", "applicationScope", "certificateLevel"};//翻译
        reservationList = translateUtil.translateList(transColum, reservationList);//翻译
        model.addAttribute("reservationList", reservationList);
        //查已预定的证书
        Map<String, Object> advanceMap = new HashMap<>();
        advanceMap.put("scOrderId", scOrderId);
        advanceMap.put("generalCredentialStatus", CredentialConstant.GENERAL_CREDENTIAL_STATUS_RESERVATION);//查已预定的
        List<GeneralCertificate> generalCertificateList = generalCredentialService.queryGertificateInfo(advanceMap);
        model.addAttribute("generalCertificateList", generalCertificateList);
        //查已匹配的证书  这里需要查询匹配和使用状态的证书
        Map<String, Object> matchMap = new HashMap<>();
        String[] generalCredentialStatusList =
                new String[]{CredentialConstant.GENERAL_CREDENTIAL_STATUS_MATCH, CredentialConstant.GENERAL_CREDENTIAL_STATUS_SUBORDINATE};
        matchMap.put("generalCredentialStatusList", generalCredentialStatusList);
        matchMap.put("scOrderId", scOrderId);
        List<GeneralCertificate> generalCertificateMatchList = generalCredentialService.queryGertificateInfo(matchMap);
        model.addAttribute("generalCertificateMatchList", generalCertificateMatchList);

        //查询已预约的资质
        Map<String, Object> storageMapZz = new HashMap<>();
        storageMapZz.put("scProductId", scOrderId);
        storageMapZz.put("generalType", CredentialConstant.ZZ_CREDENTIAL);
        storageMapZz.put("status", CredentialConstant.PRODUCT_RESERVATION_STATUS_RESERVATION);//新增预约
        List<Map> reservationListZz = reservationService.queryListByScOrderId(storageMapZz);
        String[] transColum4 = {"certificateCategory", "certificateToThree", "applicationScope", "certificateLevel"};//翻译
        reservationListZz = translateUtil.translateList(transColum4, reservationListZz);//翻译
        model.addAttribute("reservationListZz", reservationListZz);
        //查已预定的资质
        Map<String, Object> advanceMapZz = new HashMap<>();
        advanceMapZz.put("scOrderId", scOrderId);
        advanceMapZz.put("generalCredentialStatus", CredentialConstant.CERTIFICATE_APTITUDE_STATUS_TWO);
        List<Qualification> qualificationList = qualificationService.findMatchData(advanceMapZz);
        String[] transColum5 = {"areaProvince", "certificateArea", "certificateCategory", "certificateToThree", "applicationScope", "certificateLevel"};//翻译
        qualificationList = translateUtil.translateList(transColum5, qualificationList);//翻译
        model.addAttribute("qualificationList", qualificationList);
        //查已匹配的资质 包含申请转让和已转让
        Map<String, Object> matchMapZz = new HashMap<>();
        matchMapZz.put("scOrderId", scOrderId);
        String[] qualificationStatuses =
                new String[]{CredentialConstant.CERTIFICATE_APTITUDE_STATUS_THREE, CredentialConstant.CERTIFICATE_APTITUDE_STATUS_FOUR
                        , CredentialConstant.CERTIFICATE_APTITUDE_STATUS_FIVE};
        matchMapZz.put("qualificationStatuses", qualificationStatuses);
        List<Map> qualificationMatchList = qualificationService.findQualificationDetailData(matchMapZz);
        String[] transColum6 = {"areaProvince", "certificateArea", "certificateCategory", "certificateToThree", "applicationScope", "certificateLevel"};//翻译
        qualificationMatchList = translateUtil.translateList(transColum6, qualificationMatchList);//翻译 (状态没有翻译,到jsp翻译的)
        model.addAttribute("qualificationMatchList", qualificationMatchList);

        return "zzsc/inprocess/certificate_qualification_detail";
    }

    /**
     * <p>@Description 生产 详情里面保存节点备注</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/23 0023 17:45 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_product_operating_by_detail")
    @ResponseBody
    @NLog()
    public Object saveProductOperatingByDetail(@RequestParam Map params) {
        try {
            zzInProcessService.saveProductOperatingByDetail(params);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 详情页历史记录中的附件信息页面</p>
     * <p>@author mqy</p>attachment
     * <p>@Time 2018/8/23 0023 14:45 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/query_product_attachment_page")
    @NLog()
    public String queryProductAttachment(Long productOrderId, Model model) {
        model.addAttribute("productOrderId", productOrderId);
        return "zzsc/inprocess/query_product_attachment_page";
    }

    /**
     * <p>@Description 跳转到普通备注页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/16 0016 17:15 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/order_remarks")
    @NLog()
    public String orderRemarks(Long scorderId, Model model) {
        model.addAttribute("scorderId", scorderId);
        //根据id查询是否超期
        Map order = allOrderService.findOrderById(scorderId);
        //订单超期,合同超期后面会加上
        if (order != null && order.get("contractTimeStatus") != null && "OVERDUE_STATE2".equals(order.get("contractTimeStatus").toString())) {
            model.addAttribute("type", 1);
        } else if (order != null && order.get("orderTimeStatus") != null && "OVERDUE_STATE2".equals(order.get("orderTimeStatus").toString())) {
            model.addAttribute("type", 2);
        } else if (order != null && order.get("nodeTimeStatus") != null && "OVERDUE_STATE2".equals(order.get("nodeTimeStatus").toString())) {//节点超期
            model.addAttribute("type", 3);
        } else {//正常
            model.addAttribute("type", 0);
        }
        return "zzsc/inprocess/order_remarks";
    }

    /**
     * <p>@Description 跳转到普通备注批量页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/16 0016 17:15 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/order_remarks_all")
    @NLog()
    public String orderRemarksAll(String ids, Model model) {
        List<ProductOrder> list = zzInProcessService.getScProductOrderAllByIds(ids);
        model.addAttribute("orderList", list);
        return "zzsc/inprocess/order_remarks_all";
    }

    /**
     * <p>@Description 保存备注</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/16 0016 17:41 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_remarks")
    @ResponseBody
    @NLog()
    public Object saveRemarks(@RequestParam Map paramMap) {
        try {
            zzInProcessService.saveOrderRemarks(paramMap);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 批量保存备注</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/16 0016 17:41 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_remarks_all")
    @ResponseBody
    @NLog()
    public Object saveRemarksAll(@RequestParam Map paramMap) {
        try {
            JSONArray jsonArray = JSONArray.parseArray(paramMap.get("ids").toString());
            List<Long> idArray = jsonArray.toJavaList(Long.class);
            if (!CollectionUtils.isEmpty(idArray)) {
                for (Long l : idArray) {
                    Map map = new HashMap();
                    map.put("scorderId", l);
                    map.put("remark", paramMap.get("remark"));
                    zzInProcessService.saveOrderRemarks(map);
                }
            }
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 打开退单</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/17 0017 9:11 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/charge_back_order_page")
    @NLog()
    public String chargeBackOrderPage(Long id, Model model) {
        try {
            ProductOrder productOrder = this.zzInProcessService.getScProductOrderById(id);
            List list = zzCommonMangerExtService.queryTreeBookListByCode(ScProductConstant.RETURENED_REASON, 1, null);
            model.addAttribute("list", list);
            model.addAttribute("scProductOrder", productOrder);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "zzsc/inprocess/charge_back_order_page";
    }


    /**
     * <p>@Description 申请退单</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/17 0017 9:57 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("/abandon_reason_order")
    @ResponseBody
    @NLog()
    public Object abandonReasonOrder(@RequestParam Map params) {
        try {
            this.zzInProcessService.abandonReasonOrder(params);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 拨打电话的查找客户信息</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/20 0020 9:43 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/find_call_info")
    @ResponseBody
    @NLog()
    public DggRestResponse findCallInfo(Long id) {
        try {
            ProductOrder productOrder = this.zzInProcessService.getScProductOrderById(id);
            Map<String, Object> customer = new HashMap<>();
            customer.put("id", productOrder.getId());
            customer.put("name", productOrder.getCustomerName());
            Map noMap = new HashMap();
            noMap.put("phoneStr", desUtil.decrypt(productOrder.getCustomerPhone()));
            noMap = CustomerNumberEncryptionUtil.encryptionObject(new String[]{"phoneStr"}, noMap);
            customer.put("phone", productOrder.getCustomerPhone());
            customer.put("phoneStr", noMap.get("phoneStr"));
            return this.getSuccessResponse(customer);
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 获取判断界面展示内容的key</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0027 15:20 创建时间</p>
     * <p>@return</p>
     */
    private void getAcquisitionConditions(Map<String, Object> map) {
        String type = null == map.get("type") ? "" : map.get("type").toString();
        if ("toDay".equals(type)) { //今日待跟进
            map.put("toDay", "toDay");
        } else if ("currentDay".equals(type)) { //新增办理
            map.put("currentDay", "currentDay");
        } else if ("hasOverDue".equals(type)) { //超期跟进
            map.put("hasOverDue", "hasOverDue");
        } else if ("nodeOverDue".equals(type)) { //节点超期
            map.put("nodeOverDue", ScProductConstant.TIME_OUT);
        } else if ("proOverDue".equals(type)) { //订单超期
            map.put("proOverDue", ScProductConstant.TIME_OUT);
        } else if ("overDue".equals(type)) { //超期订单,包括节点,订单,合同
            if (StringUtils.isEmpty(map.get("timeStatus"))) {
                map.put("overDue", ScProductConstant.TIME_OUT);
            } else {
                map.put("all", ScProductConstant.SC_ORDER_IN_PROCESS);
            }
        } else if ("overdueWarning".equals(type)) { //预警
            map.put("overdueWarning", ScProductConstant.TIME_OUT);
        } else {
            map.put("all", ScProductConstant.SC_ORDER_IN_PROCESS); //全部
        }
    }


    /**
     * <p>@Description 根据当期登录人获取事业部及以下人员的数据</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/29 0029 18:32 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("divisionUser")
    @ResponseBody
    public Object getDivisionUser() {
        Map<String, Object> map = new HashMap<>();
        List<Map> divisionUsers = new ArrayList<>();
        //获取当前登录的人部门
        Map orgMap = zzCommonMangerExtService.findBusDeptById(sessionManager.getCurrentUser().getOrgId());
        if (orgMap != null && orgMap.size() != 0) {
            //拿到事业部及以下的部门id
            map.put("orgId", orgMap.get("id"));
            map.put("locked", 0);
            divisionUsers = zzCommonMangerExtService.searchUserByMap(map);
        }
        return divisionUsers;
    }


    /**
     * <p>@Description 获取订单来源方式</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/5 0005 14:59 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/origin_type")
    @ResponseBody
    public Object originType() {
        return zzCommonMangerExtService.queryTreeBookListByCode("SC_GENERAL_ORIGINCODE", 1, null);
    }

    /**
     * <p>@Description 移交</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/12 0012 10:50 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/turn_over_product_order")
    @NLog()
    public String turnOverProductOrder() {
        return "zzsc/inprocess/turn_over_product_order";
    }

    /**
     * <p>@Description 移交保存</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/12 0012 11:29 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("/save_turn_over")
    @ResponseBody
    @NLog
    public DggRestResponse saveTurnOver(@RequestParam Map map) {
        try {
            zzInProcessService.saveTurnOver(map);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 跳转到证书匹配页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/27 0027 15:17 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/certificate_matching_page")
    @NLog()
    public String certificateMatchingPage(Model model, Long id) {
        model.addAttribute("scOrderId", id);
        // 证书类别
        List<Map> certificateCategorys = commonService.queryTreeBook(CredentialConstant.GENERAL_CERTIFICATE_CATEGORY, 1, 2, null);
        model.addAttribute("certificateCategorys", certificateCategorys);
        // 三类证书
        List<Map> certificateToThrees = commonService.queryTreeBook(CredentialConstant.GENERAL_CERTIFICATE_TO_THREE, 1, 2, null);
        model.addAttribute("certificateToThrees", certificateToThrees);
        // 适用范围
        List<Map> applicationScopes = commonService.queryTreeBook(CredentialConstant.CREDENTIAL_APPLICATION_SCOPE, 1, 2, null);
        model.addAttribute("applicationScopes", applicationScopes);
        model.addAttribute("generalType", CredentialConstant.GENERAL_CREDENTIAL);//普通证书
        // 是否购买社保
        List<CommonVo> socialSecurity = new ArrayList<>(2);
        CommonVo commonVo1 = new CommonVo("0", "是");
        CommonVo commonVo2 = new CommonVo("1", "否");
        socialSecurity.add(commonVo1);
        socialSecurity.add(commonVo2);
        model.addAttribute("socialSecurity", socialSecurity);
        //查询已预定证书多少个
        Map<String, Object> cpMap = new HashMap<>();
        cpMap.put("scProductId", id);
        cpMap.put("generalType", CredentialConstant.GENERAL_CREDENTIAL);
        cpMap.put("generalCredentialStatus", CredentialConstant.GENERAL_CREDENTIAL_STATUS_RESERVATION);//查已预定的
        int cpNumber = qualificationService.queryQualificationProductNumber(cpMap);
        model.addAttribute("cpNumber", cpNumber);
        //查询预约证书多少个
        Map<String, Object> rnMap = new HashMap<>();
        rnMap.put("scProductId", id);
        rnMap.put("stype", CredentialConstant.GENERAL_CREDENTIAL);
        rnMap.put("status", CredentialConstant.PRODUCT_RESERVATION_STATUS_RESERVATION);
        Integer rnNumber = zzInProcessService.queryReservationNumberByProduct(rnMap);
        model.addAttribute("rnNumber", rnNumber);
        List<Integer> matchNumber = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            matchNumber.add(i + 1);
        }
        model.addAttribute("matchNumber", matchNumber);

        return "zzsc/inprocess/certificate_matching_page";
    }

    /**
     * <p>@Description 获取生产订单预定的证书或者资质数量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/31 0031 18:25 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/query_advance_match_number")
    @ResponseBody
    @NLog()
    public DggRestResponse queryAdvanceMatchNumber(Long scOrderId, int type) {
        try {
            //查询预约证书或资质多少个
            Map<String, Object> rnMap = new HashMap<>();
            rnMap.put("scProductId", scOrderId);
            rnMap.put("status", CredentialConstant.PRODUCT_RESERVATION_STATUS_RESERVATION);
            //查预定的证书或者资质
            Map<String, Object> cpMap = new HashMap<>();
            cpMap.put("scProductId", scOrderId);
            if (type == 1) {//证书
                cpMap.put("generalType", CredentialConstant.GENERAL_CREDENTIAL);
                cpMap.put("generalCredentialStatus", CredentialConstant.GENERAL_CREDENTIAL_STATUS_RESERVATION);//查已预定的
                rnMap.put("stype", CredentialConstant.GENERAL_CREDENTIAL);
            } else if (type == 2) {//资质
                cpMap.put("generalType", CredentialConstant.ZZ_CREDENTIAL);
                cpMap.put("generalCredentialStatus", CredentialConstant.CERTIFICATE_APTITUDE_STATUS_TWO);//查已预定的
                rnMap.put("stype", CredentialConstant.ZZ_CREDENTIAL);
            }
            int cpNumber = qualificationService.queryQualificationProductNumber(cpMap);
            Integer rnNumber = zzInProcessService.queryReservationNumberByProduct(rnMap);//查预约
            Map result = new HashMap<String, Object>() {{
                put("cpNumber", cpNumber);
                put("rnNumber", rnNumber);
            }};
            return this.getSuccessResponse(result);
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("0");
        }

    }

    /**
     * <p>@Description 保存证书预定</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0028 8:57 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_certificate_advance")
    @ResponseBody
    @NLog()
    public DggRestResponse saveCertificateAdvance(Long certificateId, String certificateNo, Long scOrderId, Integer type) {
        try {
            zzInProcessService.saveCertificateAdvance(certificateId, certificateNo, scOrderId, type);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * 预定并匹配 龙
     *
     * @param certificateId
     * @param certificateNo
     * @param scOrderId
     * @return
     */
    @RequestMapping(value = "/save_certificate_advance_and_match_certificate")
    @ResponseBody
    @NLog()
    public DggRestResponse saveCertificateAdvanceAndMaching(Long certificateId, String certificateNo, Long scOrderId, Long underOrderId) {
        try {
            zzInProcessService.saveAdvanceMatchCertificate(certificateId, certificateNo, scOrderId, underOrderId);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 证书匹配页面的匹配按钮:跳转到匹配详情页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0028 13:39 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/certificate_advance_match_page")
    @NLog()
    public String certificateAdvanceMatchPage(Model model, Long id) {
        model.addAttribute("scOrderId", id);
        Map<String, Object> map = new HashMap<>();
        map.put("scOrderId", id);
        map.put("generalCredentialStatus", CredentialConstant.GENERAL_CREDENTIAL_STATUS_RESERVATION);//查已预定的
        List<GeneralCertificate> generalCertificateList = generalCredentialService.queryGertificateInfo(map);
        model.addAttribute("generalCertificateList", generalCertificateList);
        return "zzsc/inprocess/certificate_advance_match_page";
    }

    /**
     * <p>@Description 证书预匹配页面按钮:跳转到证书预匹配结果详情页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0028 13:39 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/certificate_advance_matching_result")
    @NLog()
    public String openCertificateAdvanceMatchResultPage(Model model,@RequestParam Map<String,Object> map) {
        model.addAttribute("scOrderId",map.get("scOrderId"));
        model.addAllAttributes(map);
        Map params = new HashMap();
        List<String> certificateSpecialtyIds = null;
        String certificateSpecialtyId = map.get("certificateSpecialtyId").toString();
        List<String> ccc = new ArrayList<>();
        if(certificateSpecialtyId.contains("[")){
            String[] ss = certificateSpecialtyId.substring(2, certificateSpecialtyId.length() -2).replace("\"","").replace(" ","").split(",");
            for (String s:ss) {
                ccc.add(s);
            }
        } else {
            ccc = Arrays.asList(certificateSpecialtyId.substring(1, certificateSpecialtyId.length() - 1));
        }
        params.put("certificateType",map.get("certificateType"));
        params.put("certificateSpecialtysArray",ccc);
        params.put("certificateLevel",map.get("certificateLevel"));
        params.put("isAll","3");
        params.put("scOrderId",map.get("scOrderId"));
        params.put("socialSecurityAreaId",map.get("socialSecurityAreaId"));
        params.put("scCondition",1);
        List<GeneralCertificate> generalCertificateList = generalCredentialService.queryGertificateInfo(params);
        for (GeneralCertificate certificate : generalCertificateList) {
            Date affiliatedExpireTime = certificate.getAffiliatedExpireTime();
            if(null!=affiliatedExpireTime){
                String status =(affiliatedExpireTime.getTime() > System.currentTimeMillis())?"0":"1";
                certificate.setSpecialNote(status);
            }else{
                certificate.setSpecialNote("0");
            }
        }

        String[] hideColum = {"personalPhone"};//隐藏
        generalCertificateList = desUtil.decryptList(hideColum, generalCertificateList);
        generalCertificateList = CustomerNumberEncryptionUtil.encryptionList(hideColum, generalCertificateList);
        model.addAttribute("generalCertificateList",generalCertificateList);
        return "zzsc/all/certificate_advance_matching_result";
    }


    /**
     * 证书预匹配详情
     *
     * @param params
     * @param request
     * @return
     */
    @NLog()
    @RequestMapping("/query_certificate_advance_match_result")
    @ResponseBody
    public DggRestResponse queryGertificateAdvanceMatchResult(@RequestParam Map params, HttpServletRequest request) {
        try{
            DataTableRequest r = DataTableUtils.getParam(request); //获取datatable参数
            params.put("page", r.getPage());//获取当前页
            params.put("limit", r.getLength());//获取每页条数
            params.put("certificateType", params.get("certificateTypeId"));
            List<String> certificateSpecialtyIds = null;
            if (params.get("certificateSpecialtyId").toString().contains("[")) {
                certificateSpecialtyIds = Arrays.asList(params.get("certificateSpecialtyId").toString().substring(2, params.get("certificateSpecialtyId").toString().length() - 2).split("\",\""));
            } else {
                certificateSpecialtyIds = Arrays.asList(params.get("certificateSpecialtyId").toString().substring(1, params.get("certificateSpecialtyId").toString().length() - 1));
            }
            params.put("certificateSpecialtyIds", certificateSpecialtyIds);
            params.put("certificateLevel", params.get("certificateLevel"));
            params.put("socialSecurity1", params.get("isSocialSecurity"));
            params.put("socialSecurityAreaId", params.get("socialSecurityAreaId"));
            List<GeneralCertificate> generalCertificateList = generalCredentialService.queryGertificateInfo(params);
            return new net.dgg.zz.common.utils.DataTableResponse().data(params, generalCertificateList);
        } catch (CommonExcption e) {
            e.printStackTrace();
            params.put("count", 0);
            return new net.dgg.zz.common.utils.DataTableResponse().data(params, new ArrayList<GeneralCertificate>());
        }catch (Exception e) {
            e.printStackTrace();
            params.put("count", 0);
            return new net.dgg.zz.common.utils.DataTableResponse().data(params, new ArrayList<GeneralCertificate>());
        }
}



    /**
     * <p>@Description 取消预定</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0028 14:26 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/cancel_advance_certificate")
    @ResponseBody
    @NLog()
    public DggRestResponse cancelAdvanceCertificate(Long certificateId,String certificateNo, Long scOrderId, Integer type) {
        try {
            zzInProcessService.cancelAdvanceCertificate(certificateId,certificateNo, scOrderId, type);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }



    /**
     * <p>@Description 保存匹配证书</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0028 15:16 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_match_certificate")
    @ResponseBody
    @NLog()
    public DggRestResponse saveMatchCertificate(Long certificateId,String certificateNo, Long scOrderId, Integer type) {
        try {
            zzInProcessService.saveMatchCertificate(certificateId,certificateNo, scOrderId, type);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 跳转到证书预约页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/27 0027 17:04 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/certificate_appointment_page")
    @NLog()
    public String certificateAppointmentPage(Model model, Long id) {
        model.addAttribute("scOrderId", id);
        // 证书类别
        List<Map> certificateCategorys = commonService.queryTreeBook(CredentialConstant.GENERAL_CERTIFICATE_CATEGORY, 1, 2, null);
        model.addAttribute("certificateCategorys", certificateCategorys);
        // 三类证书
        List<Map> certificateToThrees = commonService.queryTreeBook(CredentialConstant.GENERAL_CERTIFICATE_TO_THREE, 1, 2, null);
        model.addAttribute("certificateToThrees", certificateToThrees);
        // 适用范围
        List<Map> applicationScopes = commonService.queryTreeBook(CredentialConstant.CREDENTIAL_APPLICATION_SCOPE, 1, 2, null);
        model.addAttribute("applicationScopes", applicationScopes);
        model.addAttribute("generalType", CredentialConstant.GENERAL_CREDENTIAL);//普通证书
        return "zzsc/inprocess/certificate_appointment_page";
    }


    /**
     * <p>@Description 异步获取生产订单预约的证书</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/3 0003 13:32 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/certificate_appointment_data")
    @ResponseBody
    @NLog()
    public net.dgg.zz.common.utils.DataTableResponse certificateAppointmentData(@RequestParam Map params, HttpServletRequest request) {
        DataTableRequest r = DataTableUtils.getParam(request); //获取datatable参数
        params.put("page", r.getPage());//获取当前页
        params.put("limit", r.getLength());//获取每页条数
        //查询已预约的证书
        params.put("scProductId", params.get("scOrderId"));
        params.put("generalType", CredentialConstant.GENERAL_CREDENTIAL);
        params.put("status", CredentialConstant.PRODUCT_RESERVATION_STATUS_RESERVATION);
        List<Map> reservationList = reservationService.queryListByScOrderId(params);
        String[] transColum = {"certificateCategory", "areaProvince",  "applicationScope", "certificateLevel"};
        reservationList = translateUtil.translateList(transColum, reservationList);//翻译
        return new net.dgg.zz.common.utils.DataTableResponse().data(params, reservationList);

    }

    /**
     * <p>@Description 保存证书预约</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0028 16:10 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_appointment_certificate")
    @ResponseBody
    @NLog()
    public DggRestResponse saveAppointmentCertificate(@RequestParam Map map) {
        try {
            zzInProcessService.saveAppointmentCertificate(map);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 取消预约证书和资质</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/29 0029 9:12 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/cancel_appointment_certificate")
    @ResponseBody
    @NLog()
    public DggRestResponse cancelAppointmentCertificate(Long scOrderId, Long resevationId) {
        try {
            zzInProcessService.cancelAppointmentCertificate(scOrderId, resevationId);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 跳转到资质匹配页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/27 0027 15:17 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/qualification_matching_page")
    @NLog()
    public String qualificationMatchingPage(Model model, Long id) {
        model.addAttribute("scOrderId", id);
        //查资质类型
        Map<String, Object> map = new HashMap<>();
        map.put("generalType", CredentialConstant.ZZ_CREDENTIAL);
        map.put("parentId", 0);
        List<Map> typeList = certificateTypeService.getCertificateType(map);
        model.addAttribute("typeList", typeList);
        //适用范围
        List<Map> applicationScopes = commonService.queryTreeBook(CredentialConstant.CREDENTIAL_APPLICATION_SCOPE, 1, 2, null);
        model.addAttribute("applicationScopes", applicationScopes);
        List<Map> certificateLevels = commonService.queryTreeBook(CredentialConstant.QUALIFICATION_LEVEL, 1, 2, null);
        model.addAttribute("certificateLevels", certificateLevels);


        //查询已预定资质多少个
        Map<String, Object> cpMap = new HashMap<>();
        cpMap.put("scProductId", id);
        cpMap.put("generalType", CredentialConstant.ZZ_CREDENTIAL);
        cpMap.put("generalCredentialStatus", CredentialConstant.CERTIFICATE_APTITUDE_STATUS_TWO);//查已预定的
        int cpNumber = qualificationService.queryQualificationProductNumber(cpMap);
        model.addAttribute("cpNumber", cpNumber);
        //查询预约资质多少个
        Map<String,Object> rnMap = new HashMap<>();
        rnMap.put("scProductId", id);
        rnMap.put("stype", CredentialConstant.ZZ_CREDENTIAL);
        rnMap.put("status", CredentialConstant.PRODUCT_RESERVATION_STATUS_RESERVATION);
        Integer rnNumber = zzInProcessService.queryReservationNumberByProduct(rnMap);
        model.addAttribute("rnNumber", rnNumber);
        return "zzsc/inprocess/qualification_matching_page";
    }


    /**
     * <p>@Description 跳转到资质预约页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0027 17:04 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/qualification_appointment_page")
    @NLog()
    public String qualificationAppointmentPage(Model model, Long id) {
        model.addAttribute("scOrderId", id);
        //查资质类型
        Map<String, Object> map = new HashMap<>();
        map.put("generalType", CredentialConstant.ZZ_CREDENTIAL);
        map.put("parentId", 0);
        List<Map> typeList = certificateTypeService.getCertificateType(map);
        model.addAttribute("typeList", typeList);
        //适用范围
        List<Map> applicationScopes = commonService.queryTreeBook(CredentialConstant.CREDENTIAL_APPLICATION_SCOPE, 1, 2, null);
        model.addAttribute("applicationScopes", applicationScopes);
        List<Map> certificateLevels = commonService.queryTreeBook(CredentialConstant.QUALIFICATION_LEVEL, 1, 2, null);
        model.addAttribute("certificateLevels", certificateLevels);
        return "zzsc/inprocess/qualification_appointment_page";
    }

    /**
     * <p>@Description 异步获取资质预约信息</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/3 0003 14:00 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/qualification_appointment_data")
    @NLog()
    @ResponseBody
    public net.dgg.zz.common.utils.DataTableResponse qualificationAppointmentData(@RequestParam Map params, HttpServletRequest request) {
        DataTableRequest r = DataTableUtils.getParam(request); //获取datatable参数
        params.put("page", r.getPage());//获取当前页
        params.put("limit", r.getLength());//获取每页条数
        //查询已预约的资质
        params.put("scProductId", params.get("scProductId"));
        params.put("generalType", CredentialConstant.ZZ_CREDENTIAL);
        params.put("status", CredentialConstant.PRODUCT_RESERVATION_STATUS_RESERVATION);
        List<Map> reservationList = reservationService.queryListByScOrderId(params);
        String[] transColum = { "certificateCategory", "certificateToThree", "applicationScope", "certificateLevel"};//翻译
        reservationList = translateUtil.translateList(transColum, reservationList);//翻译
        return new net.dgg.zz.common.utils.DataTableResponse().data(params, reservationList);
    }

    /**
     * <p>@Description 保存资质预约</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0028 16:10 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_appointment_qualification")
    @ResponseBody
    @NLog()
    public DggRestResponse saveAppointmentQualification(@RequestParam Map map) {
        try {
            zzInProcessService.saveAppointmentQualification(map);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 资质匹配页面的匹配按钮:跳转到匹配详情页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/28 0028 13:39 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/qualification_advance_match_page")
    @NLog()
    public String qualificationAdvanceMatchPage(Model model, Long id) {
        model.addAttribute("scOrderId", id);
        Map<String, Object> map = new HashMap<>();
        map.put("scOrderId", id);
        map.put("generalCredentialStatus", CredentialConstant.CERTIFICATE_APTITUDE_STATUS_TWO);//查已预定的
        List<Qualification> generalCertificateList = qualificationService.findMatchData(map);
        String[] transColum5 = { "areaProvince","certificateArea", "certificateCategory", "certificateToThree", "applicationScope", "certificateLevel"};//翻译
        generalCertificateList = translateUtil.translateList(transColum5, generalCertificateList);//翻译
        model.addAttribute("generalCertificateList", generalCertificateList);
        return "zzsc/inprocess/qualification_advance_match_page";
    }

    /**
     * <p>@Description 打开证书使用页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/30 0030 10:14 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/subordinate_certificate_page")
    @NLog()
    public String subordinateCertificatePage(Model model, Long certificateId) {
        try {
            Map map = new HashMap<String, Object>() {{
                put("certificateId", certificateId);
            }};
            Map resultMap = guidePriceConfigService.countGuidePriceBySubordinate(map);
            if (resultMap != null) {//查到了使用指导价
                model.addAttribute("hangUpGuidingPrice", resultMap.get("hangUpGuidingPrice"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "zzsc/inprocess/subordinate_certificate_page";
    }


    /**
     * <p>@Description 保存证书使用</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/30 0030 14:29 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_certificate_subordinate")
    @ResponseBody
    @NLog()
    public DggRestResponse saveCertificateSubordinate(@RequestParam Map map) {
        try {
            zzInProcessService.saveCertificateSubordinate(map);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 证书/资质的取消匹配</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/30 0030 15:53 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/cancel_match_certificate")
    @ResponseBody
    @NLog()
    public DggRestResponse cancelMatchCertificate(@RequestParam Map map) {
        try {
            zzInProcessService.cancelMatchCertificate(map);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        }  catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 证书的取消使用</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/30 0030 15:53 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/cancel_subordinate_certificate")
    @ResponseBody
    @NLog()
    public DggRestResponse cancelSubordinateCertificate(@RequestParam Map map) {
        try {
            zzInProcessService.cancelSubordinateCertificate(map);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        }  catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 打开资质转让申请页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/30 0030 10:14 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/application_transfer_page")
    @NLog()
    public String applicationTransferPage(Model model) {
        try {
            //查询资质转让审核人
            List<UserDTO> userList = zzInProcessService.findUserListByQulificationAuditor();
            model.addAttribute("userList", userList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "zzsc/inprocess/application_transfer_page";
    }


    /**
     * <p>@Description 保存资质转让申请</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/30 0030 16:48 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/save_application_transfer")
    @ResponseBody
    @NLog()
    public DggRestResponse saveApplicationTransfer(@RequestParam Map map) {
        try {
            zzInProcessService.saveApplicationTransfer(map);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        }catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
    * <p>@Description 删除生产订单相关的证书/资质预约信息</p>
    * <p>@author mqy</p>
    * <p>@Time 2018/9/7 0007 17:47 创建时间</p>
    * <p>@return</p>
    */
    @RequestMapping(value = "/delete_product_reservation_by_sc")
    @ResponseBody
    @NLog()
    public DggRestResponse deleteProductReservationBySc(Long scOrderId,Integer type) {
        try {
            zzInProcessService.deleteProductReservationBySc(scOrderId,type);//type 1证书 2资质
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        }catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * <p>@Description 删除生产订单相关的证书/资质预定信息</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/7 0007 17:47 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/cancel_advance_base_credential_by_sc")
    @ResponseBody
    @NLog()
    public DggRestResponse cancelAdvanceBaseCredentialBySc(Long scOrderId,Integer type) {
        try {
            UserEntity userEntity = sessionManager.getCurrentUser();
            zzInProcessService.cancelAdvanceBySc(scOrderId,userEntity,type);//type 1证书 2资质
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            return this.getFailResponse(e.getMessage());
        }catch (CommonExcption e) {
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }
    /**
     * <p>@Description 办理中导出</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/31 0031 16:19 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping("/export_inprocess_product_order")
    public void exportSczzAbnormal(@RequestParam Map params, HttpServletResponse response) {
        try {
            String fileName = "办理中生产订单_" + DateUtils.dateString(new Date(), "yyyyMMddHHmm") + ".xlsx";
            UserEntity userEntity = sessionManager.getCurrentUser();
            params.put("scstatus", ScProductConstant.SC_ORDER_IN_PROCESS);//办理中
            params.put("userEntity", userEntity.getId()); //当前登录人
            if (StringUtils.isNotEmpty(params.get("customerPhone"))) {
                params.put("customerPhone", desUtil.encrypt(params.get("customerPhone").toString()));
            }
            //获取判断界面展示内容的key
            getAcquisitionConditions(params);
            List<InprocessOrderVo> dataList = zzInProcessService.findExportProductOrder(params);
            ExcelUtils.writeToFile(dataList, null, fileName, response,InprocessOrderVo.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    /**
     * <p>@Description 团队办理超期页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/13 0013 11:27 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/team_inprocess_time_out")
    @NLog()
    public String teamInprocessTimeOut(Model model, String status) {
        model.addAttribute("status", !StringUtils.isEmpty(status) ? status : "all");
        model.addAttribute("proOverDue", "proOverDue"); //订单已超期
        return "zzsc/team/team_inprocess_time_out";
    }


    /**
     * <p>@Description 团队办理超期页面数据</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/13 0013 16:47 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/team_inprocess_time_out_data")
    @ResponseBody
    @NLog()
    public DataTableResponse teamInprocessTimeOutData(@RequestParam Map params, HttpServletRequest request) {
        try {
            DataTableRequest r = DataTableUtils.getParam(request);
            params.put("page", r.getPage());
            params.put("limit", r.getLength());
            List<Map> list = allOrderService.teamInprocessTimeOutData(params);
            String[] transColum = {"originCode","status"};
            list = translateUtil.translateList(transColum, list);
            String[] hideColum = {"customerPhone"};//隐藏
            list = desUtil.decryptListMap(hideColum, list);
            CustomerNumberEncryptionUtil.encryptionList(hideColum,list);
            int count = Integer.parseInt(params.get("count").toString());//总条数
            return new DataTableResponse(r.getDraw(), count, count, list, "");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    /**
     * <p>@Description 工作台办理超期界面</p>
     * <p>@author zhangwen</p>
     * <p>@Time 2018/10/26  15:27 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/exceed_list")
    @NLog()
    public String desk_index(Model model, String status) {
        model.addAttribute("status", !StringUtils.isEmpty(status) ? status : "all");
        model.addAttribute("all", "all"); //全部办理中
        model.addAttribute("toDay", "toDay"); //今日待跟进
        model.addAttribute("proOverDue", "proOverDue"); //订单已超期
        return "zzsc/inprocess/inprocess_exceed_list";
    }


    /**
     * <p>@Description 工作台办理超期信息分页列表</p>
     * <p>@author zhangwen</p>
     * <p>@Time 2018/10/26  15:27 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/query_exceed_list")
    @ResponseBody
    @NLog()
    public DataTableResponse queryExceedList(@RequestParam Map params, HttpServletRequest request) {
        try {
            UserEntity userEntity = sessionManager.getCurrentUser();
            DataTableRequest r = DataTableUtils.getParam(request); //获取datatable参数
            params.put("start", r.getStart());//获取当前页
            params.put("limit", r.getLength());//获取每页条数
            //流程人员是自己的
            params.put("flowUserId",userEntity.getId());
            //查所有订单超期的数量
            params.put("orderTimeStatus",ScProductConstant.TIME_OUT);
            //不包含（已完结、已结项、已退单、待分配）
            params.put("notStatusList",new String[]{ScProductConstant.SC_ORDER_OVER
                    ,ScProductConstant.SC_ORDER_OVER_OVERDUE,ScProductConstant.SC_ORDER_OVER_FORCE
                    ,ScProductConstant.SC_ORDER_JUNCTIONS,ScProductConstant.SC_ORDER_FINISHED_CHARGEBACK
                    ,ScProductConstant.SC_TO_RECEIVE_XDDJS,ScProductConstant.SC_ORDER_BACK_TO_ALLOT});
            if (net.dgg.zz.common.utils.StringUtils.isNotEmpty(params.get("customerPhone"))) {
                params.put("customerPhone", desUtil.encrypt(params.get("customerPhone").toString()));
            }
            //获取判断界面展示内容的key
            getAcquisitionConditions(params);
            List<Map> listPage = zzInProcessService.queryExceedListPage(params);
            String[] transColum = {"originCode", "originType", "status", "businessTypeId", "businessProductId"};
            listPage = translateUtil.translateList(transColum, listPage);//翻译
            String[] hideColum = {"customerPhone"};//解密
            listPage = desUtil.decryptListMap(hideColum, listPage);
            CustomerNumberEncryptionUtil.encryptionList(hideColum, listPage);
            Integer count = Integer.parseInt(params.get("count").toString());
            return new DataTableResponse(r.getDraw(), count, count, listPage, "");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * <p>@Description 跳转到普通备注页面</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/16 0016 17:15 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/force_order_remarks")
    @NLog()
    public String forceRemarks(Long id, Model model) {
        model.addAttribute("scorderId", id);
        //根据id查询是否超期
        Map order = allOrderService.findOrderById(id);
        //订单超期,合同超期后面会加上
        if(order!=null&&order.get("orderTimeStatus")!=null&&"OVERDUE_STATE2".equals(order.get("orderTimeStatus").toString())){
            model.addAttribute("type", 2);
        }else if(order!=null&&order.get("nodeTimeStatus")!=null&&"OVERDUE_STATE2".equals(order.get("nodeTimeStatus").toString())){//节点超期
            model.addAttribute("type", 3);
        }else{//正常
            model.addAttribute("type", 0);
        }
        return "zzsc/inprocess/force_order_remarks";
    }

    /**
     *强制完结订单
     * @param params
     * @return
     */
    @RequestMapping("/force_over_order")
    @ResponseBody
    @NLog()
    public Object forceOverProOrder(@RequestParam Map params) {
        try {
            UserEntity userEntity = sessionManager.getCurrentUser();
            this.zzInProcessService.forceOverOrder(params, userEntity);
            return this.getSuccessResponse("操作成功!");
        } catch (ProductOrderExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }
    /**
     * <p>@Description 工单iframe 页面</p>
     * <p>@return</p>
     */
    @RequestMapping("/workOrderInof")
    @NLog()
    public String workOrderInof(Long scorderId, Model model) {
        List<Node> productNodes = flowService.getNode(scorderId);
        List<Map> allRemarksNodeList = zzInProcessService.queryNodeAndRemarksNode(scorderId);
        ProductOrder scProductOrder = zzInProcessService.getScProductOrderById(scorderId);
        model.addAttribute("scProductOrderStatus", scProductOrder.getStatus());
        model.addAttribute("scorderId", scorderId);
        model.addAttribute("productNodes", productNodes);
        model.addAttribute("allRemarksNodeList", allRemarksNodeList);
        return "zzsc/inprocess/product_order_history_records";
    }

    @RequestMapping("/creatWorkOrder.html")
    public String creatWorkOrder( Model model) {
        return "zzsc/inprocess/creat_work_order";

    }

    /**
     * 获取企管家人员
     *
     * @return
     */
    @RequestMapping(value = "/getQgjUser")
    @ResponseBody
    public DggRestResponse<String> getQgjUser(@RequestParam Long orderId, @RequestParam String businessTypeId) {
        String resultMap = zzInProcessService.getQgjUser(orderId,businessTypeId);
        if (!net.dgg.iboss.base.util.StringUtils.isBlank(resultMap)) {
            return this.getSuccessResponse(resultMap);
        } else {
            return this.getFailResponse("未获取到企管家人员");
        }

    }
    @ResponseBody
    @RequestMapping(value="/get_scOrder.do")
    public DggRestResponse isScOrderExist(@RequestParam Long id){
        try {
            ProductOrder productOrder = zzInProcessService.getScProductOrderById(id);
            if(null == productOrder){
                return this.getFailResponse("未查询到生产单！");
            }else{
                return this.getSuccessResponse(null);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.getSuccessResponse("未查询到生产单！");
        }
    }
    @GetMapping("queryQGJ")
    @ResponseBody
    public DggRestResponse queryQGJ(@RequestParam Long id){
        ProductOrder productOrder = zzInProcessService.getScProductOrderById(id);
        if(null == productOrder){
            return this.getFailResponse("未查询到生产单！");
        }
        String resultMap = zzInProcessService.getQgjUser(productOrder.getOrderId(), productOrder.getBusinessTypeCode());
        if (!net.dgg.iboss.base.util.StringUtils.isBlank(resultMap)) {
            List<String> list = new ArrayList<>();
            StringBuilder sb = new StringBuilder();
            if (resultMap.contains("，")){
                String[] strings = resultMap.split("，");
                for (String string : strings) {
                    if (list.contains(string)){
                        continue;
                    }
                    list.add(string);
                }
            }
            if (list.size() != 0){
                for (int i = 0; i < list.size(); i++) {
                    if ( i == list.size() -1){
                        sb.append(list.get(i));
                    } else {
                        sb.append(list.get(i)).append(",");
                    }
                }
            }
            return this.getSuccessResponse("".equals(sb.toString()) ? resultMap : sb.toString());
        } else {
            return this.getFailResponse("抱歉， 该订单暂无企管家人员");
        }
    }

    @GetMapping("list_qgj_remark")
    public String listQgjRemark(@RequestParam Long orderId,Model model){
        model.addAttribute("orderId", orderId);
        return "zzsc/inprocess/list_qgj_remark";
    }
    @PostMapping("list_qgj")
    @ResponseBody
    public DggRestResponse queryQGJ1(@RequestParam Map params, HttpServletRequest request){
        try {
            DataTableRequest r = DataTableUtils.getParam(request);
            List listREemark = zzInProcessService.getQgjListREemark(params);
            return new net.dgg.zz.common.utils.DataTableResponse().data(params, listREemark);
        } catch (CommonExcption e) {
            e.printStackTrace();
            params.put("count", 0);
            return new net.dgg.zz.common.utils.DataTableResponse().data(params, new ArrayList<>());
        }catch (Exception e) {
            e.printStackTrace();
            params.put("count", 0);
            return new net.dgg.zz.common.utils.DataTableResponse().data(params, new ArrayList<>());
        }
    }
}
